june 2012 doc id 023195 rev 1 1/17 AN4112 application note using stm32f05xx analog compar ators in application cases introduction this document describes six application cases of the two analog comparators embedded in the ultra-low power stm32f05xx product line. the application cases are: analog voltage monitoring analog watchdog during stop mode pulse width measurement pulse width modulation (pwm) signal control capacitance measurement brightness control using a light dependent resistor (ldr) the six application cases demonstrate the usefulness of analog comparators and show how they are integrated with other peripherals, for example, the digital-to-analog-converter (dac) and timers. to ensure a quick start, four application cases presented in this document are implemented in c language and available in project\stm32f0xx_stdperiph_examples\comp within the stm32f0xx_stdperiph_lib package. please note that this document is not intended to replace the comparator section in the product reference manual rm0091 (for stm32f05xx ). the peripheral power consumption should be consulted in the device datasheets. table 1. applicable products type part numbers microcontrollers stm32f05xx www.st.com
contents AN4112 2/17 doc id 023195 rev 1 contents 1 analog voltage monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 analog watchdog during st op mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3 pulse width measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 pwm signal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5 capacitance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6 brightness control usin g a light d ependent resistor (ldr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
AN4112 list of figures doc id 023195 rev 1 3/17 list of figures figure 1. sensor output connection to comp2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 figure 2. power consumption in an analog voltage monitoring application . . . . . . . . . . . . . . . . . . . . . 5 figure 3. comp2 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 figure 4. analog comparators combined in window mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 5. analog watchdog during stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 6. comp2 with output redirection feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 figure 7. pulse width measurement: comp2 output redirection to timer . . . . . . . . . . . . . . . . . . . . . 10 figure 8. pwm signal control: comp2 output redirection to timer . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 9. rc network connection for capacitance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 10. capacitance measurement using comp2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 11. connecting an ldr resistor to an stm32f05xx device . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 12. comparator output behavior versus light intensity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
analog voltage monitoring AN4112 4/17 doc id 023195 rev 1 1 analog voltage monitoring the stm32f05xx devices embed a 12-bit analog-to-digital converter (adc) which is very fast with a sampling rate of 1 msample/s. however, with a 1.5 ma typical consumption, it can jeopardize battery life time if left powered-on continuously. it is therefore recommended to use analog comparators in application cases where the analog input voltage (sensor output) needs to be measured as soon as a pre-defined threshold is exceeded. in the stm32f05xx devices, analog comparators are useful for monitoring the analog input voltage and powering-on the adc when required. while monitoring the analog voltage, the device can enter stop mode at the same time that both comparator s are still powered on. consequently, better consumption is achieved and power is saved. note: analog comparators are powered by the internal reference voltage, v refint , which is still powered-on in stop mode. once v refint is disabled, the comparators can no longer be used. in an analog voltage monitoring application, where the sensor output voltage is lower than the threshold, the mcu remains in stop mode, thereby saving power. as soon as the sensor output exceeds the threshold, the mcu is woken up, the adc is powered on and the analog input voltage is measured. when the sensor output is under the threshold, the mcu re- enters stop mode. the average power consumption is dramatically reduced when compared with an application that continuously measures the analog voltage whatever the input value. figure 1 shows how to connect a sensor output (temperature sensor, pressure sensor, pyroelectric infrared detector, photodiode sensor) to an stm32f05xx device in an analog voltage monitoring application using comparat or 2 (comp2). comp2 monitors the analog voltage in stop mode while the adc measures it in run mode. figure 1. sensor output connection to comp2 1. adc_ch1: ac channel 1 comp2_inp: comparator 2 non-inverting input 2. only if required. 3 4 - & |